<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php echo $title ?></title>
<?php  
	foreach($styles as $style)
	{
		echo "\t".Html::style($style)."\n"; 
	} 
	
	foreach($scripts as $script)
	{
		echo "\t".Html::script($script)."\n"; 
	} 
?>
	<script type="text/javascript">
	$(document).ready(function() {
		$.datepicker.setDefaults( $.datepicker.regional[ "<?php echo $lang ?>" ] );
		$('#from').add('#to').datetimepicker({ dateFormat: 'yy-mm-dd', showSecond: true, timeFormat: 'hh:mm:ss', hourGrid: 4, minuteGrid: 10, secondGrid: 10 });
		
		$('#kohana-profiler').dialog({ width: '90%', title: 'Profiler', autoOpen: false });
		$('#profiler').click(function(){$('#kohana-profiler').dialog('open');});
		$('#profiler').button({icons: { primary: "ui-icon-signal" }});
	});
	</script>
</head>
<body>
<div id="header">
	<?php echo __('You are logged in as <b>:user</b>', array(':user' => ucfirst($user->login))) ?> |  <?php echo Html::anchor('logout', __('Logout')); ?>
	<div id="lang">
		<strong><?php echo __('Language') ?>:</strong> 
		<?php echo ($lang == 'en') ? '<strong>eng</strong>' : Html::anchor('en/', 'eng'); ?> | 
		<?php echo ($lang == 'ru') ? '<strong>rus</strong>' : Html::anchor('', 'rus'); ?>
	</div>
</div>
<div id="toolbar" class="ui-widget-header">
	<form action="" method="GET" name="diapason">
		<?php  echo __('Select date range: from :from - to :to', array(':from'=> Form::input('from', input::get('from', date('Y-m-d').' 00:00:00') , array('id' => 'from')), ':to'=>Form::input('to', input::get('to', date('Y-m-d').' 23:59:59'), array('id' => 'to')))); ?>
		<?php echo Form::submit('button', __('Search')); ?>
	</form>
</div>

<?php if(count($errors) > 0): ?>
<div id="errors">
	<?php foreach($errors as $field => $error): ?>
	<div class="ui-widget">
		<div class="ui-state-highlight ui-corner-all" style="padding: 10px;"> 
			<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
			<strong><?php echo __('Error'); ?>: </strong> <?php echo __($error, array(':field' => __($field))) ?></p>
		</div>
	</div>
	<?php endforeach; ?>
</div>
<?php endif; ?>

<table border="1">
	<colgroup span="1"><col class="oce-first" span="1"></col></colgroup>
<?php if(count($data) > 0): ?>
<?php
	$count = 0; 
	$summ = 0;
?>
	<thead>
		<tr>
		<?php foreach($user->role['params']['access_fields'] as $field): ?>
			<th><?php echo __($field); ?></th>
		<?php endforeach; ?>
		</tr>
	</thead>
	<tbody>
<?php foreach($data as $row): ?>
		<tr>
			<?php foreach($user->role['params']['access_fields'] as $field): ?>
			<td><?php
			$count++;
			
			if($field == 'date')
			{
				echo strftime('%e %b %Y, %H:%M:%S', strtotime($row->$field));
			}
			elseif($field == 'command' OR $field == 'id_iper')
			{
				echo __($row->$field);
			}
			elseif($field == 'sum')
			{
				$summ = $summ + $row->$field;
				echo NUM::format($row->$field, 2).' '.__('RUB');
			}
			elseif($field == 'params')
			{
				foreach(unserialize($row->$field) as $field => $value)
				{
					if($field == 'prv_id' AND $user->role['id'] == 'admin')
					{
						echo "<p><b> ".__($field)."</b> {$value}</p>";
					}
					elseif($field == 'sum_from')
					{
						echo "<p><b> ".__($field)."</b> ".NUM::format($value, 2)." ".__('RUB')."</p>";
					}
					elseif($field != 'prv_id')
					{
						echo "<p><b> ".__($field)."</b> {$value}</p>";
					}
				}
			}
			else
			{
				echo $row->$field;
			}

			?></td>
			<?php endforeach; ?>
		</tr>
<?php endforeach; ?>
	</tbody>
	<tfoot>
		<tr>
			<th align="right" colspan="<?php echo $count; ?>"><?php echo  __('Total'); ?>: <b><?php echo  NUM::format($summ, 2).' '.__('RUB'); ?></b></th>
		</tr>
	</tfoot>
<?php else:?>
	<tr>
		<td><?php echo __('Sorry! No data in DataBase found. Try again latter'); ?></td>
	</tr>
<?php endif;?>
	
</table>
<div id="copyright" class="ui-widget-header">
	<center>ООО "Сотаплат"</center>
</div>

<?php if(Kohana::$profiling):?>
<button id="profiler">Run Profiler</button>

<div id="kohana-profiler">
<?php echo View::factory('profiler/stats') ?>
</div>
<?php endif; ?>
</body>
</html>